
/*
 * Version No: 1.0.0
 * Created On: Mon Aug 01 12:18:58 2005
 */

/**
 *  \file at_parser_internal.h
 *
 *  This file is the header file of AT Parser Module.
 */

/*
 *  Copyright (C) 2013. Mindtree Ltd.
 *  All rights reserved.
 */

#ifndef _H_AT_PARSER_INTERNAL_
#define _H_AT_PARSER_INTERNAL_

#include "BT_at_parser_api.h"

/* ---------------------------------------------- AT Parser Debugging */
#ifndef AT_PARSER_NO_DEBUG
#define AT_PARSER_ERR(...)          BT_debug_error(BT_MODULE_ID_AT_PARSER, __VA_ARGS__)
#else   /* AT_PARSER_NO_DEBUG */
#define AT_PARSER_ERR               BT_debug_null
#endif  /* AT_PARSER_NO_DEBUG */

#ifdef AT_PARSER_DEBUG

#define AT_PARSER_TRC(...)          BT_debug_trace(BT_MODULE_ID_AT_PARSER, __VA_ARGS__)
#define AT_PARSER_INF(...)          BT_debug_info(BT_MODULE_ID_AT_PARSER, __VA_ARGS__)

#define AT_PARSER_debug_dump_bytes(data, datalen) BT_debug_dump_bytes(BT_MODULE_ID_AT_PARSER, (data), (datalen))

#else /* AT_PARSER_DEBUG */

#define AT_PARSER_TRC               BT_debug_null
#define AT_PARSER_INF               BT_debug_null

#define AT_PARSER_debug_dump_bytes(data, datalen)

#endif /* AT_PARSER_DEBUG */

/* ------------------------------------------ Global Definitions/Constants */

#define FINAL_STATE     0xFFFF

/* Macro for incrementing AT string current index */
#define MULTIPLE_INCREMENT(x, v)\
{ \
    (x) += (v); \
    if((x) >= global_buffer_size) \
    { \
        (x) -= global_buffer_size; \
    } \
}

#define INCREMENT(x) \
{ \
    (x) ++; \
    if((x) > parser_response->global_buffer_size) \
    { \
        (x) = parser_response->global_buffer_size; \
    } \
}

#define DECREMENT(x) \
{ \
    if(0 != (x)) \
    { \
        (x) --; \
    } \
}


/* --------------------------------------------- Global Definitions */
#define FINAL_TR_STATE          0xFE
#define INVALID_TR_STATE        0xFF

#define UNKNOWN_TR_STATE        0xBF


/* --------------------------------------------- Structures/Data Types */
typedef API_RESULT (* AT_FN_PTR)
                   (
                       AT_PARSER_RESPONSE *parser_response,
                       UCHAR min_len,
                       UCHAR max_len,
                       UCHAR *count,
                       UINT16 *start_index
                   );

typedef struct
{
    AT_FN_PTR  fn_ptr;
    UCHAR      success_state;
    UCHAR      failure_state;
    UCHAR      min_len;
    UCHAR      max_len;

} AT_JUMP_TABLE;

typedef struct
{
    UCHAR input;
    UCHAR next_state;

} AT_TRANSITION_TABLE;

typedef struct
{
    UCHAR table_index;
    UCHAR count;

} AT_LOOKUP_TABLE;

/* --------------------------------------------- Internal Functions */

#define AT_DECL_HANDLER(x)            \
API_RESULT x                          \
           (                          \
               AT_PARSER_RESPONSE *,  \
               UCHAR,                 \
               UCHAR,                 \
               UCHAR *,               \
               UINT16 *               \
           )

AT_DECL_HANDLER (at_is_string);
AT_DECL_HANDLER (at_is_digit);
AT_DECL_HANDLER (at_is_cind);
AT_DECL_HANDLER (at_is_chld);
AT_DECL_HANDLER (at_is_binary);
AT_DECL_HANDLER (at_is_comma);
AT_DECL_HANDLER (at_is_dtmf);
AT_DECL_HANDLER (at_dummy_transition);
AT_DECL_HANDLER (at_is_bind);

API_RESULT at_is_open_list
           (
               AT_PARSER_RESPONSE *  parser_response,
               UCHAR                 min_len,
               UCHAR                 max_len,
               UCHAR              *  count,
               UINT16             *  start_index
           );

void at_skip_white_spaces
     (
         AT_PARSER_RESPONSE *    parser_response
     );

void at_fill_response_param
     (
         AT_PARAM *  param,
         UINT16      start_of_value_index,
         UCHAR       value_length,
         UCHAR       param_type,
         UCHAR       optional_nesting_level
     );

#endif /* _H_AT_PARSER_INTERNAL_ */

